#include "rfid_app.h"
#include "user_wwdg.h"
#include "event_app.h"
#include "basic_app.h"
#include "sound_app.h"
#include "safety_app.h"
#include "memroy_app.h"
#include "gtx31x_app.h"
#include "user_system.h"
#include "battery_app.h"
#include "network_app.h"
#include "protocol_app.h"
#include "bluetooth_app.h"
#include "real_time_app.h"

int main(void)
{
#if (defined(DCDC_ENABLE)) && (DCDC_ENABLE == TRUE)
  PWR_DCDCCfg(ENABLE);
#endif

  HSECFG_Capacitance(HSECap_20p);//fix 18 to 20
  SetSysClock(CLK_SOURCE_HSE_PLL_62_4MHz);


#if (defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
  GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD);
  GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD);
#endif

#if DEBUG
  GPIOA_SetBits(bTXD1);
  GPIOA_ModeCfg(bTXD1, GPIO_ModeOut_PP_5mA);
  UART1_DefInit();

  GetLastResetStatus();
#endif

  BluetoothLibraryInit();
  HardwareInit();
  GAPRole_PeripheralInit();
  BluetoothPeripheralInit();

  WwdgConfiguration();
  MemoryConfiguartion();
  BatteryConfiguration();
  RealTimeConfiguration();
  ProtocolConfiguration();
  EventCenterConfiguration();

  RfidConfiguration();
  BasicConfiguration();
  SoundConfiguration();
  SafetyConfiguration();
  Gtx31xConfiguration();
  NetworkConfiguration();

  EventSystemStartup();
  Set_EmergenFg(false);
  while (1)
  {
    WwdgFeedWatchdog();
    EventDataHandler();

    TMOS_SystemProcess();
  }

  return 0;
}
